<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>切换图片</title>
		<style>
			div#d1{
				border: 2px dotted red;
			}
		</style>
		<script>
			function shiftImage(t){
				//t.value
				var d=document.getElementById("adv1");
				//d.src="images/"+t.value+".jpg";
				d.setAttribute("src","images/"+t.value+".jpg");
			}
			function addImg(){
				var d=document.createElement("img");
				d.setAttribute("src","images/3.jpg");
				d.setAttribute("height","300px");
				d.setAttribute("width","500px");
				document.getElementById("d1").appendChild(d);
				//document.body.appendChild(d);
			}
			function cloneImg(){
				var d=document.getElementById("d1");
				var d2=d.cloneNode(true);
				document.body.appendChild(d2);
			}
			function delDiv(){
				console.log(document.body.lastElementChild.nodeName+":"+document.body.lastElementChild.nodeType);
				document.body.removeChild(document.body.lastElementChild);
				
			}
		</script>
	</head>
	<body>
		<input type="button" value="添加一张图片" onclick="addImg()"/>
		<input type="button" value="克隆d1" onclick="cloneImg()"/>
		<input type="button" value="删除最后一个div" onclick="delDiv()"/>
		<input type="radio" name="shiftpic" checked="checked" value="1" onclick="shiftImage(this)"/>小狗
		<input type="radio" name="shiftpic" value="2" onclick="shiftImage(this)"/>灰霾
		<div id="d1">
			<img src="images/1.jpg" id="adv1"/>
		</div>
		
	</body>
</html>
